import api from '@/libs/request'
import type { PageInfo } from './model'

/**
 * 分类页查询分类
 * @param {string} ids
 * @param {string} categoryLevel(平台端)
 */
export const doGetCategoryLevelFromPlatform = (ids: string[], categoryLevel: string) => {
  return api.get('gruul-mall-addon-platform/platform/category/by/ids', { ids: ids.join(','), categoryLevel })
}
type PageConfig = {
  current: number
  pages: number
  size: number
}
/**
 * 根据二级分类id查询商品(平台)
 */
export const doGetCommodityBySecCateIdFromPlatform = (ids: string, categoryLevel: string, pageConfig: PageConfig) => {
  const { current, pages, size } = pageConfig
  return api.get('gruul-mall-addon-platform/platform/category/by/platformCategoryId', {
    ids,
    categoryLevel,
    current,
    pages,
    size,
  })
}
/**
 * 获取首页装修数据
 */

export const doGetPlatformDec = () => {
  return api.get<PageInfo>('gruul-mall-addon-platform/platform/decoration/client/page/info')
}

/**
 * 获取O2O装修数据
 */

export const doGetPlatformLocal = () => {
  return api.get('gruul-mall-addon-platform/platform/decoration/client/local/info')
}

/**
 * 获取除首页装修以外装修数据
 */
export enum FUNCTIONTYPE {
  TABBAR,
  CLASSIFY_PAGE,
  PERSONAL_CENTER,
}
export const doGetExcludePageDec = (functionType: keyof typeof FUNCTIONTYPE) => {
  return api.get(`gruul-mall-addon-platform/platform/decoration/client/type/info?functionType=${functionType}`)
}
/**
 * 通过页面Id获取装修组件
 * @param {string} id
 * @param {Long} shopId
 */
export const doGetDecorationComponentsById = (id: string, shopId: Long) => {
  return api.get(
    `gruul-mall-addon-platform/platform/decoration/get?id=${id}`,
    {},
    {
      'Shop-Id': shopId,
    },
  )
}
/**
 * 根据页面类型获取已启用的模板的对应页面
 * @param {string} type
 */
export const doGetEnablePageByType = (endpointType: string, type: string) => {
  return api.get(`gruul-mall-addon-platform/pages/opening-up/${endpointType}/${type}`)
}
/**
 * 根据页面id获取平台装修页面详情（主要为自定义页面）
 */
export const doGetPlatformPagesDetail = (id: string) => {
  return api.get(`gruul-mall-addon-platform/pages/${id}`)
}
